<%@ page language="java" import="java.util.*" pageEncoding="utf-8" isELIgnored="false"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
 <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%> 
 <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> 
 <%@ taglib prefix="s" uri="http://www.springframework.org/tags" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head> 
    <link rel="stylesheet" href="<s:url value="/resources"/>/css/common.css" type="text/css" />
    <link rel="stylesheet" href="<s:url value="/resources"/>/css/innerstyle.css" type="text/css" />   
    <link rel="stylesheet" type="text/css" media="screen" href="<s:url value="/resources"/>/css/cupertino/jquery-ui.custom.min.css" />
	<script type="text/javascript" src="<s:url value="/resources"/>/js/jquery-1.7.2.min.js"></script>
	<script type="text/javascript" src="<s:url value="/resources"/>/js/jquery-ui.custom.min.js"></script> 
	<script type="text/javascript" src="<s:url value="/resources"/>/js/jquery.form.js"></script>
	<script type="text/javascript" src="<s:url value="/resources"/>/js/json2.js"></script>
	<script type="text/javascript" src="<s:url value="/resources"/>/js/jquery.validate.min.js"></script>
	<script type="text/javascript" src="<s:url value="/resources"/>/js/messages_zh.js"></script>
	<script type="text/javascript" src="<s:url value="/resources"/>/js/i18n/jquery.ui.datepicker-zh-CN.js"></script>
<style type="text/css">
	.content_gridview
	{
		margin:0px;	
		padding:0px;
		width:99%;
		text-align:left;
		font-size:12px;
		border-left:#cad1dd 1px solid;
		border-top:#cad1dd 1px solid;
		border-color:"#000";
	}
	.content_gridview th
	{
		padding:0px;
		
		height:26px;
		line-height:26px;
		text-align:center;
		
		border-right:#cad1dd 1px solid;
		border-bottom:#cad1dd 1px solid;
		border-color:"#000";
		/* background-image:url(../images/th.gif); */
		background-repeat:repeat-x;
		background-position:top;
	}
	
	.content_gridview td
	{
		padding:0px;
		height:24px;
		line-height:24px;
		text-align:center;
		border-right:#cad1dd 1px solid;
		border-bottom:#cad1dd 1px solid;
		border-color:"#000";
	}
	
	.longtextbox
	{
		width:320px;
		border:#cad1dd 1px solid;
	}
	
	.textarea
	{
	    overflow:auto;	
		border:#cad1dd 1px solid;
			
	}
	
	label.error {
	color: red; /*错误信息的颜色*/
	}
	
	input.error {
		border: 1px dotted red; /*输入错误的输入框的边框样式*/
	}
</style>
<script type='text/javascript'>
	$(function(){ 
	    $("#but_save").button();
	    $("#but_res").button(); 
	    $("#but_back").button(); 
	    jiaoyan();
	    loadFhdwData();
	    loadShdwData();
	    $("#fayrq").datepicker({dateFormat:'yy-mm-dd'});
		//为提交按钮绑定事件
	    $("#but_save").click(function () {
             //$("#dialog-confirm").dialog("open");
             $( "#dialog-confirm" ).dialog({
                        resizable: false,
					    //autoOpen: false,            
						height:140,
						modal: true,
						buttons: {
							"确认": function() {
							     save();
							},
							"返回": function() {
								$( this ).dialog( "close" );
							}
						}
					}); 
          });
     });
     
   //保存
	function save(){
	   if($("#form1").valid()){ 
	        var url = "<s:url value="/hwjs"/>/updateFyd";
	         $("#form1").ajaxSubmit({
	              url:url,
	              type:'post',
	              success:function(data){
		              var ret = eval('(' + data + ')');
		              alert(ret.msg);
		              if(ret.success==true)
		              {
		                 window.location.href="<s:url value="/hwjs"/>/directFyddb";
		              }
	              }		              
	         });
	     }
	}
	
	//保存
	function saveFydAndJfd(){
	   if($("#form1").valid()){ 
	        var url = "<s:url value="/hwjs"/>/saveFydAndJfd";
	         $("#form1").ajaxSubmit({
	              url:url,
	              type:'post',
	              success:function(data){
		              var ret = eval('(' + data + ')');
		              alert(ret.msg);
		              if(ret.success==true)
		              {
		                 window.location.href="<s:url value="/hwjs"/>/directFyddb";
		              }
	              }		              
	         });
	     }
	}
	
	
	//联想发货单位
	function loadFhdwData() {
		var url = "<s:url value="/"/>/common/loadFhdw";
		$.get(url, function(data) {
			var projects = eval('(' + data + ')');
			$("#fahdw").autocomplete({
				minLength : 2,
				source : projects,
				select : function(event, ui) {	
					$("#fahdw").val(ui.item.label);
					$("#fahdwid").val(ui.item.value);
					return false;
				}
			});
		});
	}
	
	//联想收货单位
	function loadShdwData() {
		var url = "<s:url value="/"/>/common/loadShdw";
		$.get(url, function(data) {
			var projects = eval('(' + data + ')');
			$("#shouhdw").autocomplete({
				minLength : 2,
				source : projects,
				select : function(event, ui) {	
					$("#shouhdw").val(ui.item.label);
					$("#shouhdwid").val(ui.item.value);
					return false;
				}
			});
		});
	}
	
	//校验
	function jiaoyan()
	{
        $("#form1").validate({
	       rules: {
	       "pizhh": "required",	   
	       "chumr": "required",	  
	       "maishr": "required",	  
	       "fahdw": "required",	  
	       "shouhdw": "required",	
	       "fazh": "required",
	       "daozh": "required",
	       "meizh": "required", 
	       "pinm": "required", 
	       "faydsh":{
		       required: true, 
		       number:true
	       },
	       "faychsh":{
		       required: true, 
		       number:true
	       },
	       "fayrq": "required"  
	       },
		   messages: {
			   "pizhh":"必须选择相应的铁路计划号",
		       "chumr":"必须填写出卖人",
		       "maishr":"必须填写出卖人",
		       "fahdw":"必须填写发货单位",
		       "shouhdw":"必须填写收货单位",
		       "fazh":"必须填写发站",
		       "daozh":"必须填写到站",
		       "meizh":"必须填写煤种",
		       "pinm":"必须填写品种",
			   "faydsh":{
			       required: "请输入发运吨数", 
			       number:"请输入合法数字"
		       },
			   "faychsh":{
				   required:"请输入发运车数",
				   number:"请输入合法数字"
			   }, 
			   "fayrq":"必须填写发运日期"	   
		   }
	     });
	}
	
	//打开合同
	function opentljs() { //打开铁路计划选择界面
	  openwindow('<s:url value="/hwjs"/>/openTljs','500','700');
	}
	
	function openwindow(url,sheight,swidth){
       var winoption ="dialogHeight:"+sheight+"px;dialogWidth:"+ swidth +"px;status:yes;scroll:yes;resizable:yes;center:yes";
       window.showModalDialog(url,window,winoption);
    }
    
    function changeMeizh(){
	    //给名称赋值
	    $("#meizh").val($("#meizhid").find("option:selected").text());
    }
	
	
	 function changePinm(){
	    //给名称赋值
	    $("#pinm").val($("#pinmid").find("option:selected").text());
    }
	</script>
  </head>
  
 <body>
<div id="best1">
<h2><span>发运单单笔录入</span></h2>
<form name="form1" id="form1">
    <input type="hidden" id="sysid" name="sysid" value="${fyd.sysid}"/>
    <input type="hidden" id="dingid" name="dingid" value="${fyd.dingid}"/>
    <table  align="center" cellpadding="0" cellspacing="0" class="content_gridview">
          <tr>
              <td colspan="4" style="text-align:left;">
                <span style="color: red;font-size:12px;vertical-align:left;">
	             &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*收货单位、发货单位请输入关键字进行搜索
		        </span>
              </td>
          </tr>
          <tr>
               <td>铁路计划号：</td>
               <td style="text-align:left"><input type="text" id="tieljhh" name="pizhh" class="longtextbox" readonly="readonly" value="${fyd.pizhh}"/>&nbsp;&nbsp;&nbsp;<a href='#' style='color:#0404bc' onclick='opentljs();'>选择</a></td>
               <td>&nbsp;</td>
               <td>&nbsp;</td>
          </tr>
          <tr>
               <td>出卖人：</td>
               <td style="text-align:left"><input type="text" id="chumr" name="chumr" class="longtextbox" readonly="readonly" value="${fyd.chumr}"/></td>
               <input type="hidden" id="chumrid" name="chumrid" value="${fyd.chumrid}"/>
               <td>买受人：</td>
               <td style="text-align:left"><input type="text" id="maishr" name="maishr" class="longtextbox" readonly="readonly" value="${fyd.maishr}"/></td>
               <input type="hidden" id="maishrid" name="maishrid" value="${fyd.maishrid}"/>
           </tr>
           <tr>
               <td>发货单位：</td>
               <td style="text-align:left"><input type="text" id="fahdw" name="fahdw" class="longtextbox"  value="${fyd.maishr}" /></td>
               <input type="hidden" id="fahdwid" name="fahdwid"  value="${fyd.maishr}"/>
               <td>收货单位:</td>
               <td style="text-align:left"><input type="text" id="shouhdw" name="shouhdw" class="longtextbox"  value="${fyd.maishr}"/></td>
               <input type="hidden" id="shouhdwid" name="shouhdwid" value="${fyd.maishr}"/>
           </tr>
           <tr>
               <td><span style="color: red;font-size:16px;vertical-align:middle;">*</span>发站：</td>
               <td style="text-align:left"><input type="text" id="fazh" name="fazh" class="longtextbox" readonly="readonly" value="${fyd.fazh}"/></td>
                <input type="hidden" id="fazhid" name="fazhid" value="${fyd.fazhid}"/>
               <td><span style="color: red;font-size:16px;vertical-align:middle;">*</span>到站：</td>
               <td style="text-align:left"><input type="text" id="daozh" name="daozh" class="longtextbox" readonly="readonly" value="${fyd.daozh}" /></td>
               <input type="hidden" id="daozhid" name="daozhid" value="${fyd.daozhid}"/>
           </tr>
            <tr>
               <td><span style="color: red;font-size:16px;vertical-align:middle;">*</span>煤种：</td>
               <td style="text-align:left">
               <div class="select">
					<div>
						<select name="meizhid" style="width:180px" onchange="changeMeizh()">
							<c:forEach var="mz" items="${meizhList}">
								<option value="${mz.diccode}" <c:if test="${mz.diccode==fyd.meizhid}">selected="selected"</c:if>>${mz.dicname}</option>
							</c:forEach>
						</select>
					</div>
				 </div>
            	</td>
               <input type="hidden" id="meizh" name="meizh"/>
               <td><span style="color: red;font-size:16px;vertical-align:middle;">*</span>品种：</td>
               <td style="text-align:left">
               <div class="select"><div>
            	<select id="pinmid" name="pinmid" style="width:180px" onchange="changePinm()">
                   <c:forEach var="pz" items="${pinzList}">
                   <option value="${pz.diccode}"  <c:if test="${pz.diccode==fyd.pinmid}">selected="selected"</c:if> >
                   ${pz.dicname}
                   </option>
                   </c:forEach>
                 </select>            	
            	</div></div>
            	</td>
               <input type="hidden" id="pinm" name="pinm"/>
           </tr>
           <tr>
               <td><span style="color: red;font-size:16px;vertical-align:middle;">*</span>发运吨数：</td>
               <td style="text-align:left"><input type="text" id="faydsh" name="faydsh" class="longtextbox" value="${fyd.faydsh}" /></td>
               <td><span style="color: red;font-size:16px;vertical-align:middle;">*</span>发运车数：</td>
               <td style="text-align:left"><input type="text" id="faychsh" name="faychsh" class="longtextbox" value="${fyd.faychsh}"/></td>
           </tr>
            <tr>
               <td><span style="color: red;font-size:16px;vertical-align:middle;">*</span>发运日期：</td>
               <td style="text-align:left"><input type="text" id="fayrq" name="fayrq" class="longtextbox" value="${fyd.fayrq}"/></td>
               <td>矿厂</td>
               <td style="text-align:left"><input type="text" name="kuangch" class="longtextbox" value="${fyd.kuangch}"/></td>
           </tr>
           <tr>
               <td>质量指标：</td>
               <td colspan="3" style="text-align:left"><textarea cols="110"  name="zhilzhb" rows="6"  class="textarea">${fyd.zhilzhb}</textarea></td>
           </tr>
            <tr>
               <td>注备：</td>
               <td colspan="3" style="text-align:left"><textarea cols="110"  name="beizh" rows="6"  class="textarea">${fyd.beizh}</textarea></td>
           </tr>
           <tr>
		    <td colspan="4" style="text-align:right">		    
			    <input id="but_save" type="button" value="保存" />&nbsp;&nbsp;&nbsp;
			    <input id="but_res" type="reset" value="重置" "/>&nbsp;&nbsp;&nbsp;
			    <input id="but_back" type="button" name="" value="返回" onclick="javascript:history.back();"/>
		    </td>
     </table>
</form>
</div> 
<div id="dialog-confirm" title="是否确认保存？"></div>
  </body>
</html>
